<template>
    <input type="text" :value="currentValue" @input="handleInput" @blur="handleBlur" />
</template>
<script>
import Emitter from "../../emitter";

export default {
  name: "iInput",
  mixins: [Emitter],
  props: {
    value: {
      type: String,
      default: ""
    },
    bval: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      currentValue: this.value
    };
  },
  watch: {
    value(val) {
      this.currentValue = val;
    }
  },
  methods: {
    handleInput(event) {
      const value = event.target.value;
      this.currentValue = value;
      this.$emit("input", value); // 这一步是提供给v-model的语法糖的，没有这个就不能同步到v-model的那个值
      this.dispatch("iFormItem", "on-form-change", value);
    },
    handleBlur() {
      this.dispatch("iFormItem", "on-form-blur", this.currentValue);
    }
  }
};
</script>